package com.order.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * 令牌配置类
 *
 * @Author Daft_V
 * @Date 2022/5/15 17:31
 */
@Configuration
public class TokenConfig {

    @Value("${oauth.tokenKey}")
    String tokenKey;

    /**
     * 将TokenStore注入到Bean里
     * 采用jwt对称加密
     *
     * @return TokenStore
     */
    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(accessTokenConverter());
    }

    /**
     * jwt令牌生成配置
     *
     * @return
     */
    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        // 对称密钥加密算法
        converter.setSigningKey(tokenKey);
        return converter;
    }

}
